package eScrum.pages;

import java.util.Iterator;
import java.util.List;

import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;

import eScrum.entities.User;
import eScrum.entities.UserSearchCriteria;
import eScrum.services.UserService;



public class UserDataProvider implements IDataProvider<User> {
	private static final long serialVersionUID = 1L;

	UserService userService;

	private UserSearchCriteria userSearchCriteria;

	public UserDataProvider(UserSearchCriteria userSearchCriteria, UserService userService) {
		this.userService = userService;
		this.userSearchCriteria = userSearchCriteria;
	}

	protected List<User> getUsers() {
		return userService.findAll();
	}

	public void detach() {

	}

	public Iterator<User> iterator(int first, int count) {
		return userService.findUsersByRange(first, count, userSearchCriteria ).iterator();
	}

	public int size() {
		return (int) userService.userSize(userSearchCriteria);
	}

	public IModel<User> model(User object) {
		return new DetachableUserModel(object, userService);
	}

}
